import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:活动安排
 * User: wangxin
 * Date: 2024-10-15
 * Time: 22:51
 */
public class test2 {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        ArrayList<int[]> list = new ArrayList<>();
        for(int i = 0; i < n; i++){
            int[] arr = new int[3];
            arr[0] = input.nextInt();
            arr[1] = input.nextInt();
            list.add(arr);
        }
        //这一步最重要，将给的活动排序，排序规则为按活动结束时间从小到大排，如果结束时间相同，再按照开始时间从小到大排
        //这样做最贪
        list.sort((o1, o2) -> {
            int num = o1[1] - o2[1];
            num = num==0?(o1[0] - o2[0]):num;
            return num;
        });
        int end = 0;
        int sum = 0;
        for (int[] ints : list) {
            if (ints[0] >= end) {
                sum++;
                end = ints[1];
            }
        }
        System.out.println(sum);
    }
}
